//
// Created by tang on 23-4-1.
//

#include "xxt_bus_plugin.hpp"
#include "content/image.hpp"
#include "plugin/plugin_impl.hpp"
#include "service/render_service.hpp"
#include <core/log.hpp>

const PluginInfo *XxtBusPlugin::get_plugin_info () const
{
    return &kPluginInfo;
}

bool XxtBusPlugin::initialize ()
{
    RESOURCE_IMAGE (icon_, "/icons/xxt.png");

    // ui
    auto const content = MY_RESOURCE->get_file_content ("/layouts/test_ui.xml");
    if (!content.empty ())
    {
        view_ = ServiceManager::instance ()->request_service<IRenderService> ()->create_view_from_data (content.data (), content.size ());
    }

    if (view_)
        view_->bind (&data_);

    return true;
}

void XxtBusPlugin::tick (pi_time_t delta, pi_time_t total) {
    // L_INFO("%s: delta=%.4f, total=%.4f", __FUNCTION__, delta, total);
}

void XxtBusPlugin::cleanup ()
{
    delete icon_;
}

const char * XxtBusPlugin::name () const
{
    return "行讯通 🚌";
}

const ImageContent *XxtBusPlugin::icon () const
{
    return icon_;
}

ui_view *XxtBusPlugin::content () const
{
    return view_;
}
